package _binary_search;

/**
 * 367. 有效的完全平方数
 */
public class No367 {
    public boolean isPerfectSquare(int num) {
        int left = 1, right = Math.min(num, 1 << 16);
        while (left <= right) {
            int mid = left + (right - left) / 2;
            long cur = (long) mid * mid;
            if (cur == num) return true;
            else if (cur < num) left = mid + 1;
            else right = mid - 1;
        }
        return false;
    }
}